#include "../include/value.h"
#include "../include/string.h"

void TValue_Print(const TValue *value)
{
    switch (value->category)
    {
    case T_INTEGER:
        printf("%ld", value->value.integer);
        break;
    case T_DECIMAL:
        printf("%lf", value->value.decimal);
        break;
    case T_BOOLEAN:
        printf("%s", value->value.boolean == true ? "true" : "false");
        break;
    case T_STRING:
        printf("%s", ((String *)value->value.object)->array);
        break;
    case T_NULL:
        printf("null");
        break;
    default:
        break;
    }
}

bool TValue_Equals(const TValue *v1, const TValue *v2)
{
    bool result = v1->category == v2->category && (*(_long *)(&v1->value) == *(_long *)(&v2->value));
    if (!result && v1->category == T_STRING && v2->category == T_STRING)
    {
        result = String_Equal((String *)v1->value.object, (String *)v2->value.object);
    }
    return result;
}
